#include<stdio.h>
#include<unistd.h>
#include<string.h>

/*
 *
28行和36行随便注释其中一行 就可以让read达到阻塞状态
 */

int main(){
	int ret;
	int fd[2];
	char buf[5] = {0};

	//创建无名管道
	ret = pipe(fd);
	if(ret < 0){
		perror("pipe");
		return -1;
	}

	pid_t pid = fork();
	if(pid < 0){
		perror("fork");
		return -1;
	}else if(pid == 0){
		close(fd[0]);
		close(fd[1]);
		while(1){
			//子进程 写
			strcpy(buf,"abc");
			//write(fd[1], buf, strlen(buf));
			sleep(1);
		}
	}else{
		//close(fd[1]);
		while(1){
			//父进程  读
			ret = read(fd[0], buf, 5);
			if(ret > 0){
				printf("str : %s\n", buf);
			}else if(ret == 0){
				printf("ret=0\n");
			}
		}
	}

}
